Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wrapper for widget in Dashboard #3281

Merged
merged 14 commits into from
Apr 13, 2018

Conversation

ZitaNemeckova
Copy link
Contributor

@ZitaNemeckova ZitaNemeckova commented Jan 19, 2018

TODO:

  • Add wrapper
  • Resolve GET request failure
  • Remove all old code
  • Add spinner

Error widget:
screen shot 2018-02-07 at 2 22 50 pm
Spinner widget (it spins):
screen shot 2018-02-07 at 2 23 58 pm

@miq-bot add_label wip, dashboards, gaprindashvili/no

@miq-bot miq-bot changed the title Add wrapper for widget in Dashboard [WIP] Add wrapper for widget in Dashboard Jan 19, 2018
@ZitaNemeckova ZitaNemeckova force-pushed the widget_cleanup branch 2 times, most recently from 4287e38 to 6b5b2d0 Compare February 8, 2018 14:31
@ZitaNemeckova
Copy link
Contributor Author

@himdel please have a look, thanks :)

%widget-wrapper{"widget-id" => presenter.widget.id,
"widget-type" => presenter.widget.content_type,
"widget-buttons" => presenter.widget_buttons,
"widget_blank" => widget_blank,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

widget-blank ;)

};
}],
template: [
'<div id="{{vm.divId}}">',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ng-attr-id for all those id={{.. please ;)

' </h2>',
' </div>',
' </div>',
' <widget-error ng-if="vm.error === true"></widget-error>',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace..

@ZitaNemeckova ZitaNemeckova force-pushed the widget_cleanup branch 4 times, most recently from b1505a8 to 20b0b88 Compare February 19, 2018 12:30
@ZitaNemeckova
Copy link
Contributor Author

@miq-bot remove_label wip

@miq-bot miq-bot changed the title [WIP] Add wrapper for widget in Dashboard Add wrapper for widget in Dashboard Feb 19, 2018
@miq-bot miq-bot removed the wip label Feb 19, 2018
@ZitaNemeckova
Copy link
Contributor Author

@karelhala please review, thanks :)

Copy link
Contributor

@karelhala karelhala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codewise looks good, however consider moving widget wrapper inside haml file and use angularTemplateUrl so we get HTML highlights.

Also @ZitaNemeckova it would be even better if this would have been moved to common pack if possible. So we get to use ES6 goodies and have more readable code.

template: [
'<div class="card-pf-footer">',
__('Updated'),
"{{vm.widgetLastRun}}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use single quotes.

' <td>',
' <a title="' + __("Click to go this location") + '" href="{{shortcut.href}}">',
' </div>',
' <tr ng-if="!vm.shortcutsMissing()" ng-repeat="shortcut in vm.widgetModel.shortcuts">',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the ng-if, if sortcuts has length of 0 ng-repeat will repeat zero times.

' </div>',
' <tr ng-if="!vm.shortcutsMissing()" ng-repeat="shortcut in vm.widgetModel.shortcuts">',
' <td>',
' <a title="' + __("Click to go this location") + '" href="{{shortcut.href}}">',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use ng-attr-title to make it more readable. Also use ng-href so angular has time to work with it.

<a ng-attr-title="{{__("Click to go this location")}}" ng-href="{{shortcut.href}}">

' </div>',
' <widget-error ng-if="vm.error === true"></widget-error>',
' <widget-spinner ng-if="!vm.widgetModel && vm.widgetBlank == \'false\' && !vm.error"></widget-spinner>',
' <div ng-if="vm.widgetBlank === \'true\' || vm.widgetModel" class="mc" id="{{vm.innerDivId}}" ng-class="{ hidden: vm.widgetModel.minimized }">',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can join class and ng-class together and use ng-attr-id so angular has time to work correctly:

<div ng-if="vm.widgetBlank === \'true\' || vm.widgetModel" ng-attr-id="{{vm.innerDivId}}" ng-class="{ hidden: vm.widgetModel.minimized, mc: true }">

ng-attr-id

}
};
}],
template: [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to place this HTML inside static haml file and load is using template-url?

vm.widgetUrl = function() {
switch (vm.widgetType) {
case 'menu':
return '/dashboard/widget_menu_data/' + vm.widgetId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use constants for these strings.

var dashboard = 'dashboard';
var widgetTypes = {
 menu: 'widget_menu_data';
 report: 'widget_report_data';
 chart: 'widget_chart_data';
 rss: 'widget_rss_data';
}
// ...
var buildURL = function(type) {
  return ['dashboard', type, vm.widgetId].join('/');
}

And use it inside widgetUrl as

vm.widgetUrl = function() {
  if(widgetTypes.hasOwnProperty(vm.widgetType)) {
    return buildURL(widgetTypes[vm.widgetType]);
  } else {
    console.log('Something went wrong. There is no support for widget type of ', vm.widgetType);
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's preferred to have a whole url to make it easier to find it. That's why it's not pretty.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it still makes sense to use an object instead of a switch. But yes, please keep the whole url together, this will be a part of the component definition later.

@ZitaNemeckova
Copy link
Contributor Author

@karelhala Agreed but I would prefer to move it in follow-up PR. And for moving HTML from components to haml it breaks specs because haml isn't compiled. Otherwise I fixed it as you suggested. Thanks :)

@martinpovolny
Copy link
Member

@karelhala : Can we merge this one?

@karelhala
Copy link
Contributor

@martinpovolny sure go ahead, I forgot to mark is as OK.

' </div>',
' <tr ng-repeat="shortcut in vm.widgetModel.shortcuts">',
' <td>',
' <a ng-attr-title="{{__("Click to go this location")}}" ng-href="{{shortcut.href}}">',
Copy link
Contributor

@himdel himdel Apr 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZitaNemeckova this was better as it used to be. You can't use __ inside of {{. (And no reason to use ng-attr-title for a static string.)

(Or you need to do $scope.__ = __; in this controller.)

template: [
'<div class="blank-slate-pf" style="padding: 10px">',
' <div class="blank-slate-pf-icon">',
' <i class="fa fa-spin fa-spinner"></i>',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing 2 spaces ;)

' <td>',
' <a title="' + __("Click to go this location") + '" href="{{shortcut.href}}">',
' <a title="' +__("Click to go this location")+ '" ng-href="{{shortcut.href}}">',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces

Use ng-class, ng-attr-, ng-class, ng-href
Move urls from switch to object (pretty)
Mock missing setupVerticalNavigation function from PatternFly
@himdel
Copy link
Contributor

himdel commented Apr 10, 2018

Tried clicking on the "Zoom in" button...

Error text:

Missing partial dashboard/_widget_footer, application/_widget_footer with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee, :haml, :rjs]}. Searched in: * "/home/himdel/manageiq-ui-classic/app/views" * "/home/himdel/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/bundler/gems/miq_v2v_ui_plugin-cd901ff708d5/app/views" [dashboard/widget_zoom]

So.. looks like you can't remove widget_footer it quite yet .. or better, you can convert the other use too ;)

app/views/dashboard/_zoomed_chart.html.haml
14:    = render :partial => 'widget_footer', :locals => {:widget => widget}

@ZitaNemeckova
Copy link
Contributor Author

Fixed issue with footer (see here) and same id warnings.

Replace one partial call with widget-footer component, move lightbox-panel on same level as notification-app, move last_run and next_run to helper(no duplication of code) and fix same id warnings
@miq-bot
Copy link
Member

miq-bot commented Apr 12, 2018

Checked commits ZitaNemeckova/manageiq-ui-classic@7b67b85~...0c94918 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
6 files checked, 3 offenses detected

**

  • 💣 💥 🔥 🚒 - Linter/Haml - Linter::Haml STDERR:
warning: parser/current is loading parser/ruby23, which recognizes
warning: 2.3.6-compliant syntax, but you are running 2.3.3.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.

app/helpers/dashboard_helper.rb

@himdel himdel added this to the Sprint 84 Ending Apr 23, 2018 milestone Apr 13, 2018
@himdel
Copy link
Contributor

himdel commented Apr 13, 2018

LGTM, I can press all the buttons now :)

The footer spacing around the " | " between the 2 dates changed a bit, but this is just less extra whitespace, no problem 👍

@himdel himdel merged commit f9f90f9 into ManageIQ:master Apr 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants